# Maintainer: Andy Gross <andy.gross@linaro.org>

pkgname=dtc
pkgver=1.6.0
pkgrel=3
pkgdesc="Device Tree Compiler"
arch=('i686' 'x86_64')
url="https://git.kernel.org/pub/scm/utils/dtc/dtc/git"
license=('GPL2')
depends=('libyaml')
makedepends=('python-devel' 'swig' 'libyaml-devel')
source=("https://git.kernel.org/pub/scm/utils/dtc/dtc.git/snapshot/${pkgname}-${pkgver}.tar.gz"
        01-correct-shared-library-extension.patch
        02-pyext-install.patch)
sha256sums=('3d15dee7126a6c4a015ab47ec908cab13e39774b0315efaaebb223cb4a4d349c'
            'c0dd05748bac0d5fd859c9684da58b44acdbc2ac359642c630c75bcec8cbb84d'
            '0135724ce6f5a30a381d2097bc6afa561168bdc16c42608fcc34c3990fa5b990')

prepare() {
  cd "${srcdir}/${pkgname}-${pkgver}"
  sed -i 's/python\b/python3/' tests/run_tests.sh

  # to make check work
  sed -i 's/__attribute__((weak))//' tests/testutils.c
  sed -i 's|#include <valgrind/|//#include <valgrind/|' tests/testutils.c
  sed -i 's|VALGRIND_|//VALGRIND_|' tests/testutils.c
  patch -p1 -i "${srcdir}/01-correct-shared-library-extension.patch"
  patch -p1 -i "${srcdir}/02-pyext-install.patch"
}

build() {
  cd "${srcdir}/${pkgname}-${pkgver}"
  make
}

check() {
  cd "${srcdir}/${pkgname}-${pkgver}"
  make check
}

package() {
  cd "${srcdir}/${pkgname}-${pkgver}"
  make -j1 PREFIX=/usr DESTDIR="${pkgdir}" install

  # license
  install -Dm644 ${srcdir}/${pkgname}-${pkgver}/README.license ${pkgdir}/usr/share/licenses/${pkgname}/README.license
}

